package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.SkuInfo;
import com.atguigu.gmall.product.entity.SpuImage;
import com.atguigu.gmall.product.entity.SpuSaleAttr;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.atguigu.gmall.product.service.SpuImageService;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import com.atguigu.gmall.product.vo.SkuSaveVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: SkuController
 * @Author: WDD
 * @CreateTime: 2022-12-03  15:48
 * @Description:
 */
@Api("sku管理")
@RestController
@RequestMapping("/admin/product/")
public class SkuController {

    @Autowired
    SkuInfoService skuInfoService;

    @ApiOperation("上架")
    @GetMapping("/onSale/{skuId}")
    public Result up(@PathVariable("skuId") Long skuId){
        skuInfoService.upGoods(skuId);
        return Result.ok();
    }

    @ApiOperation("下架")
    @GetMapping("/cancelSale/{skuId}")
    public Result down(@PathVariable("skuId") Long skuId){
        skuInfoService.downGoods(skuId);
        return Result.ok();
    }

    @ApiOperation("添加sku")
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuSaveVo skuSaveVo){
        skuInfoService.saveSkuInfo(skuSaveVo);
        return Result.ok();
    }

    @ApiOperation("获取sku分页列表")
    @GetMapping("list/{page}/{limit}")
    public Result skuPage(@PathVariable("page") Long page,@PathVariable("limit") Long limit){
        Page<SkuInfo> skuPage = skuInfoService.page(new Page<SkuInfo>(page,limit));
        return Result.ok(skuPage);
    }


}
